require(['validator'], function () {
    var $right = $("#alarmSettingArticle"),
        corpId = "no";
    var $sysSettingForm = $('#sysSettingForm');
    $sysSettingForm.initForm();
    // 左侧树
    commonFun.leftTreeNodeClickObj['sysAlarmCorpIdSet'] = function (event, treeId, treeNode) {
        corpId = treeNode.corpId;
        if (treeNode.level == 0) {
            corpId = "";
        }
        $("#corpId").val(corpId);
        initRight();
    };

    $(window).on('resize', function () {
    	$right.height($(window).height() - 67);
    }).trigger('resize');

    var initRight = function () {
    	$("#spdingLevel1").prop("checked", false);
    	$("#spdingLevel2").prop("checked", false);
    	$("#spdingLevel3").prop("checked", false);
    	var node = commonFun.getLeftTreeSelectedNodes();
    	if(node && node.length > 0){
    		corpId = node[0].corpId;
    		$.ajaxExt({
    			async: false,
    			url: "/alarmPushSetting/searchAlarmSpeedSetting.htm",
    			data: {"corpId": corpId}
    		}).done(function (data) {
    			console.info(data);
    			if (data && data[0]) {
//            	$sysSettingForm.setValues(data);
    				if(data[0].spdingLevel1=='1') $("#spdingLevel1").prop("checked", true);
    				if(data[0].spdingLevel2=='1') $("#spdingLevel2").prop("checked", true);
    				if(data[0].spdingLevel3=='1') $("#spdingLevel3").prop("checked", true);
    			} 
    		});
    	}
    	
    };

    $("#saveSetting").on("click", function () { // 保存
    	if(corpId=='no' || corpId == ''){
    		$.messager.alert("提示", "请选择左侧树企业。", "info");
    		return;
    	}
        var result = $.validator($sysSettingForm);
//        var formVal = $sysSettingForm.getValues();
        var data = {};
        data.corpId = corpId;
        data.spdingLevel1 = $("#spdingLevel1").is(':checked')? $("#spdingLevel1").val() : "0";
        data.spdingLevel2 = $("#spdingLevel2").is(':checked')? $("#spdingLevel2").val() : "0";
        data.spdingLevel3 = $("#spdingLevel3").is(':checked')? $("#spdingLevel3").val() : "0";
        if (result) {
        	$.ajaxExt({
                url: "/alarmPushSetting/setAlarmSpeed.htm",
                data: data
            }).done(function (data) {
                initRight();
                $.messager.alert("提示", "保存成功。", "info");
            });
        }
    });
    $("#resetSetting").on("click", function () { // 重置
        initRight();
    });

    initRight();
    
});